<template>
    <div>
        <tableList
            :apis="apis"
            :searchItems="searchItems"
            :headItems="headItems"
            :formItems="formItems"
            @actButEvent="actButEvent"
        ></tableList>
    </div>
</template>

<script>
    export default {
        name: "lidar-list",
        data() {
            return {
                apis: {
                    list: {
                        url: this.$api.V2X_LIDAR_GET,
                        params: {
                            with: 'lidarTypes;locations',
                            sortedBy: 'desc',
                            orderBy: 'id'
                        }
                    },
                    add: this.$api.V2X_LIDAR_POST,
                    update: this.$api.V2X_LIDAR_PATCH,
                    delete: this.$api.V2X_LIDAR_DELETE
                },
                searchItems: [
                    {
                        key: 'name',
                        label: this.$t('public.form.name'),
                        placeholder: this.$t('public.form.name'),
                    },
                    {
                        type: "daterange",
                        key: "date",
                        splaceholder: "",
                        eplaceholder: ""
                    }
                ],
                headItems: [
                    { key: 'lidar_id', label: this.$t('page.lidar.list.headItems.lidar_id')},
                    { key: 'name', label: this.$t('page.lidar.list.headItems.name')},
                    { key: 'mac', label: this.$t('page.lidar.list.headItems.mac') },
                    { key: 'ip', label: this.$t('page.lidar.list.headItems.ip') },
                    { key: 'lidar_types.lidar_name', label: this.$t('page.lidar.list.headItems.lidar_types') },
                    { key: 'angle', label: this.$t('page.lidar.list.headItems.angle') },
                    { key: 'height', label: this.$t('page.lidar.list.headItems.height') },
                    { key: 'locations.location_name', label: this.$t('page.lidar.list.headItems.location_name') },
                    { key: 'is_fault', label: this.$t('page.lidar.list.headItems.is_fault') ,type: 'dict'},
                    { key: 'fault_code', label: this.$t('page.lidar.list.headItems.errcode') },
                    { key: 'setup_time', label: this.$t('page.lidar.list.headItems.setup_time'), type: 'datetime' },
                    { key: 'connect_time', label: this.$t('page.lidar.list.headItems.connect_time'), type: 'datetime' },
                    { key: 'created_at', label: this.$t('public.form.created_at'), type: 'datetime' },
                ],
                formItems: [
                    {
                        key: "lidar_id",
                        label: this.$t('page.lidar.list.headItems.lidar_id'),
                        rule: ["NotBlank"]
                    },
                    {
                        key: "name",
                        label: this.$t('page.lidar.list.headItems.name'),
                        rule: ["NotBlank"]
                    },
                    {
                        key: "mac",
                        label: this.$t('page.lidar.list.headItems.mac'),
                        rule: ["NotBlank"]
                    },
                    {
                        key: "ip",
                        label: this.$t('page.lidar.list.headItems.ip'),
                        rule: ["NotBlank"]
                    },
                    {
                        key: "lidar_type",
                        label: this.$t('page.lidar.list.headItems.lidar_types'),
                        rule: ["NotBlank"],
                        type: "select",
                        optionsUrl: this.$api.V2X_LIDAR_TYPE_GET,
                        optLabel: "lidar_name",
                        optValue: "lidar_type"
                    },
                    {
                        key: "angle",
                        label: this.$t('page.lidar.list.headItems.angle'),
                        rule: ["NotBlank"]
                    },
                    {
                        key: "height",
                        label: this.$t('page.lidar.list.headItems.height'),
                        rule: ["NotBlank"]
                    },
                    {
                        key: "local_id",
                        label: this.$t('page.lidar.list.headItems.location_name'),
                        rule: ["NotBlank"],
                        type: "select",
                        optionsUrl: this.$api.V2X_LOCATION_GET,
                        optLabel: "location_name",
                        optValue: "local_id"
                    },
                    {
                        key: "setup_time",
                        label: this.$t('page.lidar.list.headItems.setup_time'),
                        rule: ["NotBlank"],
                        type: "datetime",
                    }
                ],
                formData: {},
            }
        },
        mounted() {
        },
        methods: {
            searchEvent(e) {
                console.log(e)
            },
            actButEvent(e) {
                this[e.eventName](e.val);
            },
            detailAct(e) {
                this.actStatus = e.status;
                this.title = e.time;
                this.id = e.id;
                this.apisAddDeduction.list.params.id = e.id;
                this.dialogDetailActVisible = true;
                this.formLoading = true;
                this.detailHeader();
                this.apisDetailAct.list.params.id = e.id;
                this.apisDetailAct.export.params.id = e.id;
                this.apisDetailAct.total.params.id = e.id;
            },
        }
    }
</script>

<style scoped>

</style>
